package cn.chat.ai.chatai.utils;

import com.zhipu.oapi.service.v4.model.ChatMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ChatService {
    private static final ExecutorService executorService = Executors.newFixedThreadPool(10);
    private static final Logger log = LoggerFactory.getLogger(ChatService.class);

    public static void main(String[] args) {
        String input = """
                我将提供给你一份csv格式的数据内容和一份该数据内容的json格式的结构，请帮我把数据内容转为json格式输出，并请按以下要求输出：                                                                         \s
                                                                                           \s
                ```                                                                        \s
                1.请将结构中的logicalName和数据内容对应起来，输出结果的key，请用结构中的physicalName来表示                                                                        \s
                2.结构中logicalName表示逻辑名,physicalName表示物理名，type表示类型，isList表示是否为列表(默认为false|空)                                                                         \s
                3.如果某一项结构的logicalName在数据内容中没有找到，输出时则输出null                                                                         \s
                4.CSV中的逗号分隔值按照JSON结构进行相应的嵌套和列表化处理                                                                          \s
                5.直接输出结果，不要有多余的描述和解释                                                                           \s
                ```                                                                        \s
                                                                                           \s
                数据内容：                                                                          \s
                ```                                                                        \s
                xxx村使用村级集体经济发展基金发展集体经济申请审批表,,,,,,,,,,,,,,,,,,,
                申请村名,张三,,联系方式,18888888888,,,,,,,,,,,,,,,
                申请金额,6000,,投资类别,☑ 自用,□ 投资入股,,,,,,,,,,,,,,
                申请用途,□ 种植业,□ 养殖业,□ 农村电商,□ 农产品加工,☑ 农旅结合,,,,,,,,,,,,,,
                "协议签订
                 入股
                 起止日期",入股日期: 2023年08月22日 退股日期: 2024年09月06日,,,,,,,,,,,,,,,,,,
                "约定利益
                 方式",☑保底分红,□ 保底分红+二次返利,是否有抵押,☑ 是,□ 否,,,,,,,,,,,,,,
                "协议年分
                 红日期和
                 金额",年分红日期,,年分红金额,,,,,,,,,,,,,,,,
                ,2023 年 04月 01日,,2000,,,,,,,,,,,,,,,,
                ,2023 年 05月 01日,,2000,,,,,,,,,,,,,,,,
                ,2023 年 07月 01日,,2000,,,,,,,,,,,,,,,,
                "村集体经济组织审核意见:\s
                                
                      把租金补齐",,,,,,,,,,,,,,,,,,,
                ,,,,,,,,,,,,,,,,,,,
                ,,,,,,,,,,,,,,,,,,,
                ,,,,,,,,,,,,,,,,,,,
                ,,,,,,,,,,,,,,,,,,,
                "张榜公示结果意见：
                  经公示无异议。
                                
                                
                                
                                
                 监事长签字: 张三",,,,,,,,,,,,,,,,,,,                                                                         \s
                ```                                                                        \s
                                                                                           \s
                结构：                                                                        \s
                ```                                                                        \s
                {"id": "8672254204575749", "logical_name": "_审批表", "physical_name": "B000089", "version": 1, "status": "draft", "type": "Object", "bill_type": "common", "is_parent_bill": 1, "attr": [{"id": "8672254204641285", "data_type_id": "8672254204575749", "logical_name": "申请村名", "display_name": "申请村名", "physical_name": "B000089001", "description": null, "attr_type_id": "1", "is_list": 0, "sort_no": 0, "type": "TEXT"}, {"id": "8672254204641286", "data_type_id": "8672254204575749", "logical_name": "联系方式", "display_name": "联系方式", "physical_name": "B000089002", "description": null, "attr_type_id": "1", "is_list": 0, "sort_no": 1, "type": "TEXT"}, {"id": "8672254204641287", "data_type_id": "8672254204575749", "logical_name": "申请金额", "display_name": "申请金额", "physical_name": "B000089003", "description": null, "attr_type_id": "4", "is_list": 0, "sort_no": 2, "type": "CURRENCY"}, {"id": "8672254204641288", "data_type_id": "8672254204575749", "logical_name": "投资类别", "display_name": "投资类别", "physical_name": "B000089004", "description": null, "attr_type_id": "1", "is_list": 0, "sort_no": 3, "type": "TEXT"}, {"id": "8672254204641289", "data_type_id": "8672254204575749", "logical_name": "申请用途", "display_name": "申请用途", "physical_name": "B000089005", "description": null, "attr_type_id": "1", "is_list": 0, "sort_no": 4, "type": "TEXT"}, {"id": "8672254204641290", "data_type_id": "8672254204575749", "logical_name": "入股开始日期", "display_name": "入股开始日期", "physical_name": "B000089006", "description": null, "attr_type_id": "5", "is_list": 0, "sort_no": 5, "type": "DATE"}, {"id": "8672254204641291", "data_type_id": "8672254204575749", "logical_name": "入股截止日期", "display_name": "入股截止日期", "physical_name": "B000089007", "description": null, "attr_type_id": "5", "is_list": 0, "sort_no": 6, "type": "DATE"}, {"id": "8672254204641292", "data_type_id": "8672254204575749", "logical_name": "约定利益方式", "display_name": "约定利益方式", "physical_name": "B000089008", "description": null, "attr_type_id": "1", "is_list": 0, "sort_no": 7, "type": "TEXT"}, {"id": "8672254204641293", "data_type_id": "8672254204575749", "logical_name": "协议年分红日期和金额", "display_name": "协议年分红日期和金额", "physical_name": "B000089009", "description": null, "attr_type_id": "8672229418926085", "is_list": 1, "sort_no": 8, "type": "Object", "attr": [{"id": "8672229419057157", "data_type_id": "8672229418926085", "logical_name": "年份", "display_name": "分红年份", "physical_name": "FH001", "description": null, "attr_type_id": "5", "is_list": 0, "sort_no": 0, "type": "DATE"}, {"id": "8672229419057158", "data_type_id": "8672229418926085", "logical_name": "金额", "display_name": "金额", "physical_name": "FH002", "description": null, "attr_type_id": "4", "is_list": 0, "sort_no": 1, "type": "CURRENCY"}]}, {"id": "8672254204641294", "data_type_id": "8672254204575749", "logical_name": "村集体经济组织审核意见", "display_name": "村集体经济组织审核意见", "physical_name": "B000089010", "description": null, "attr_type_id": "1", "is_list": 0, "sort_no": 9, "type": "TEXT"}, {"id": "8672254204641295", "data_type_id": "8672254204575749", "logical_name": "张榜公式意见", "display_name": "张榜公式意见", "physical_name": "B000089011", "description": null, "attr_type_id": "1", "is_list": 0, "sort_no": 10, "type": "TEXT"}, {"id": "8672254204641296", "data_type_id": "8672254204575749", "logical_name": "是否监事长签字", "display_name": "是否监事长签字", "physical_name": "B000089012", "description": null, "attr_type_id": "3", "is_list": 0, "sort_no": 11, "type": "BOOLEAN"}, {"id": "8672254204641297", "data_type_id": "8672254204575749", "logical_name": "票据编号", "display_name": null, "physical_name": "hidden_no", "description": null, "attr_type_id": "1", "is_list": 0, "sort_no": 12, "type": "TEXT"}]}
                ```                                                                        \s
                """;
        List<ChatMessage> messages = new ArrayList<>();
        //CompletableFuture<String> glm4Response = CompletableFuture.supplyAsync(() -> ChatAiClient.GLM4.chat(input, messages));
        //CompletableFuture<String> kimiResponse = CompletableFuture.supplyAsync(() -> ChatAiClient.Kimi.chat(input, messages));
        CompletableFuture<String> lavaResponse = CompletableFuture.supplyAsync(() -> ChatAiClient.OpenAI.createLlava().chat(input, messages));
        //CompletableFuture<Void> voidCompletableFuture = CompletableFuture.allOf(glm4Response, kimiResponse,lavaResponse);
        CompletableFuture<Void> voidCompletableFuture = CompletableFuture.allOf(lavaResponse);
        voidCompletableFuture.join();
        try {
            //log.info("GLM4: {}", glm4Response.get());
            //log.info("Kimi: {}", kimiResponse.get());
            log.info("Llava: {}", lavaResponse.get());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        executorService.shutdown();
    }
}
